package gold.digger;

import gold.vo.ListNode;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC328 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public ListNode oddEvenList(ListNode head) {
            if (null == head || null == head.next) return head;
            ListNode odd = head, oddCur = head, even = head.next, evenCur = head.next;
            while (evenCur != null) {
                oddCur.next = null == oddCur.next ? null : oddCur.next.next;
                evenCur.next = null == evenCur.next ? null : evenCur.next.next;
                oddCur = oddCur.next == null ? oddCur : oddCur.next;
                evenCur = evenCur.next;
            }

            oddCur.next = even;
            return odd;
        }
    }

    public void run() {
        Solution an = new Solution();
        ListNode head = ListNode.createList("1->2->3->4->5");
        System.out.println(an.oddEvenList(head));
    }


    public static void main(String[] args) throws Exception {
        LC328 an = new LC328();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
